home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Headers / dbkit / DBDatabase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-07  |  5.7 KB  |  208 lines

  1. /*
  2. **      DBDatabase.h
  3. **      Database Kit, Release 3.0
  4. **      Copyright (c) 1992, NeXT Computer, Inc.  All rights reserved. 
  5. */
  6.  
  7. #import <objc/Object.h>
  8. #import <dbkit/protocols.h>
  9. #import <mach/cthreads.h>
  10.  
  11. @class List;
  12. @class DBBinder;
  13.  
  14. /*
  15. ** A Database represents a (potential) connection to an external source of
  16. **  data.  It also represents structural information about that source of
  17. **  data.  This structural information is represented as a list of properties.
  18. **  (See the protocols header for a description of a property.)
  19. **
  20. ** Properties can either be built from scratch by a tool or by a program, or
  21. **  they can be provided by the DBDatabase.  In the latter case, the complexity
  22. **  and completeness of the data dictionary is totally dependant upon the
  23. **  database; most will produce a very simple model which reflects their 
  24. **  structure.
  25. **
  26. ** Given an expressive enough query language, properties can also be built
  27. **  by using DBExpressions -- aggregate and compound properties can be built
  28. **  this way.
  29. */
  30.  
  31. @interface DBDatabase : Object
  32. {
  33. @public
  34.   id delegate;
  35.  
  36. @private
  37.   id _adaptor;
  38.   mutex_t _adaptorLock;
  39.  
  40.   id _entityList;
  41.   id _bundle;
  42.   id _strings;
  43.  
  44.   id _databaseNameString;
  45.   char *_namebuf;
  46.   id _identityProperty;
  47.  
  48.   id _private;
  49.   struct {
  50. #if    __BIG_ENDIAN__
  51.     BOOL connected:1;
  52.     BOOL panelsEnabled:1;
  53.     BOOL delegateDoesTrace:1;
  54.     BOOL delegateChecksQuery:1;
  55.     BOOL transactionInProgress:1;
  56.     BOOL useOuterJoins:1;
  57.     BOOL isAsciiFormat:1;
  58.     int _RESERVED:9;
  59. #else    __BIG_ENDIAN__
  60.     int _RESERVED:9;
  61.     BOOL isAsciiFormat:1;
  62.     BOOL useOuterJoins:1;
  63.     BOOL transactionInProgress:1;
  64.     BOOL delegateChecksQuery:1;
  65.     BOOL delegateDoesTrace:1;
  66.     BOOL panelsEnabled:1;
  67.     BOOL connected:1;
  68. #endif    __BIG_ENDIAN__
  69.   } _flags;
  70.   NXZone *_garbageZone;
  71. }
  72.  
  73. + initialize;
  74.  
  75. /*
  76. ** If there is an open db with this name, it is returned.  If there is a
  77. **  database file in the search path with this name, it is opened and a
  78. **  connection is attempted.  If the connection attempt fails, the 
  79. **  database is freed, so subsequent calls will attempt to connect again,
  80. **  possibly using new information...
  81. **
  82. ** Databases found using this method should not be freed!
  83. */
  84. + findDatabaseNamed:(const char*)aName connect:(BOOL)yn;
  85.  
  86. /*
  87. ** Databases can use database "bundles" that reside in the filesystem to
  88. **  initialize themselves with user and schema information.  The documents are
  89. **  directories (with a file extension of .db) that contain at least two
  90. **  files: db.strings and db.archive.
  91. **
  92. ** Within the bundle, db.strings is a stringTable that can contain a string
  93. **  with the key "AdaptorName".  It can also contain multiple initStrings,
  94. **  indexed by username.  A key of "LoginString" will be used as a default
  95. **  loginString.
  96. */
  97. + (const char**)databaseNamesForAdaptor:(const char*)anAdaptorName;
  98. + (const char**)adaptorNames;
  99.  
  100. - initFromFile:(const char*)aPath;
  101. - (const char*)directory;
  102.  
  103. - (const char*)name;
  104. - (BOOL)setName:(const char*)aName;
  105.  
  106. - adaptor;
  107.  
  108. - (BOOL)connect;
  109. - (BOOL)disconnect;
  110. - (BOOL)connectUsingString:(const unsigned char*)aString;
  111. - (BOOL)disconnectUsingString:(const unsigned char*)aString;
  112.  
  113. - (BOOL)isConnected;
  114. - (const unsigned char*)connectionName;
  115.  
  116. - (BOOL)beginTransaction;
  117. - (BOOL)commitTransaction;
  118. - (BOOL)rollbackTransaction;
  119.  
  120. - (BOOL)isTransactionInProgress;
  121. - (BOOL)enableTransactions:(BOOL)yn;
  122. - (BOOL)areTransactionsEnabled;
  123.  
  124. - (BOOL)evaluateString:(const unsigned char*)aString;
  125.  
  126. - (List*)getEntities:(List*)aList;
  127. - (id<DBEntities>)entityNamed:(const char*)aName;
  128.  
  129. /*
  130. ** These can be used to find information specific to the current db bundle.
  131. */
  132. - (const char*)currentAdaptorName;
  133. - (const char*)defaultAdaptorName;
  134. - (const unsigned char*)currentLoginString;
  135. - (const unsigned char*)defaultLoginString;
  136. - (const unsigned char*)loginStringForUser:(const char*)aUser;
  137.  
  138. /*
  139. ** This can be used to launch a login panel, or to use a specific adaptor
  140. **  in the context of a database.  The init string can be NULL.
  141. */
  142. - (BOOL)connectUsingAdaptor:(const char*)aClassname
  143.     andString:(const unsigned char*)aLoginString;
  144.  
  145. /*
  146. ** -emptyDataDictionary will free up the currently loaded data dictionary
  147. **  so that another can be opened for the db.  -loadDefaultDataDictionary
  148. **  will attempt to load a data dictionary from the adaptor if one is
  149. **  not already loaded.
  150. */
  151. - emptyDataDictionary;
  152. - loadDefaultDataDictionary;
  153.  
  154. /*
  155. ** Delegate can act as trace of execution, log all query expressions, or
  156. **  verify query expressions. It can also override commits and aborts.
  157. */
  158. - setDelegate:aDelegate;
  159. - delegate;
  160.  
  161. @end
  162.  
  163. @interface Object (DatabaseDelegate)
  164.  
  165. /*
  166. ** Commit/abort verification -- no cancelling allowed!
  167. */
  168. - dbWillCommitTransaction:aDatabase;
  169. - dbDidCommitTransaction:aDatabase;
  170. - dbWillRollbackTransaction:aDatabase;
  171. - dbDidRollbackTransaction:aDatabase;
  172.  
  173. /*
  174. ** Query interposition -- before evaluating an expression, the delegate can
  175. **  be given the chance to override a query expression, to examine it, or
  176. **  to replace it.
  177. */
  178. - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString
  179.      usingBinder:aBinder;
  180.  
  181. /*
  182. ** Logging -- the delegate receives a printf style format string and
  183. **  arguments, to be used with vsprintf().
  184. */
  185. - db:aDatabase log:(const char*)fmt, ...;
  186.  
  187. /*
  188. ** Notification -- an object being used by the database has encountered
  189. **  an exceptional situation.
  190. **
  191. ** By providing a delegate that responds to this method, the default alert
  192. **  panels can be squelched.
  193. */
  194. - (BOOL)db:aDb notificationFrom:anObject
  195.      message:(const unsigned char*)msg code:(int)n;
  196.  
  197. /*
  198. ** setPanelsEnabled:NO must be called if you plan to use the DBDatabase
  199. **  without panels or windows, or in a program without an Application object.
  200. */
  201. - (BOOL)arePanelsEnabled;
  202. - setPanelsEnabled:(BOOL)yn;
  203.  
  204. - read:(NXTypedStream*)ts;
  205. - write:(NXTypedStream*)ts;
  206.  
  207. @end
  208.